<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .d1 {
            width: 400px;
            height: 400px;
            margin: 0 auto;
            
        }

        #d2 {
            width: 200px;
            height: 200px;
            background-color: black;
            color: #fff
        }
    </style>
</head>

<body>
    <div class="d1">

        
        <p>属性: <input type="text" value="background"></p>
        <p>属性值: <input type="text" value="black"></p>
        <button onclick="qd()">确定</button>
        <button onclick="cz()">重置</button>
        <div id="d2">
            点击确定改变样式
        </div>
    </div>
</body>

</html>
<script>
    var changeStyle = function (elem, name, value) {
        elem.style[name] = value
    }
    var d = document.getElementById('d2')
    var ipt = document.getElementsByTagName('input')
    function qd() {
        changeStyle(d, ipt[0].value, ipt[1].value)
    }
</script>